home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
olrdrs
/
nnrnews1.zip
/
NNRNEWS.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1994-06-10
|
17KB
|
399 lines
{
NNRNEWS.PAS ver. 1.00 - May 23, 1994. Programmed in Turbo Pascal 6.0 by
Henrik Rosen¢ (*)
--
| Henrik Rosen¢, MSc. | Tel: + 45 35 36 52 76 | East or West, |
| N¢rrebrogade 49C, 1.tv. | FAX: + 45 35 26 25 93 | Cyberspace is |
| 2200 Copenhagen N - DENMARK | e-mail: hero@login.dkuug.dk | best - HeRo |
NNRNEWS.PAS Copyright (c) 1994 Henrik Rosen¢.
License conditions:
This program is freeware and distributed as a TP 6.0 source file.
I do not take any responsibility for the consequences of compiling or
running the program. Alteration and redistribution is allowed, as long
as the file is only altered below the following line.
--------------------------------------------------------------------------
NNRNEWS convertes files saved by nn into rnews-batches (according
to RFC-1036 section 4.3), by inserting the '#! rnews <x>'-line before
the headers of all the postings in the file. When saved by nn, the
messages are simply separated by an empty line. It has been tested,
that Yarn v0.65 can import these rnews-batches.
The program requires access to FLIP.EXE, to work!
(FTP or download FLIP from somewhere, for instance as
textutil/flip1exe.zip at SimTel mirrors.)
The nnrnews command:
nnrnews [searchstring [directory]]
searchstring The files to be processed ex. *.doc.
Default is *.*
(At least on DR DOS 6.0 *.* does not work!)
directory The directory to be searched for files to convert.
Default is current directory on default drive.
When compiled in TP 6.0, this program cuts down lines to 255 characters.
Some header lines (especially Path: and Xref:, but also Newsgroups:) are
longer than 255 characters, and are damaged.
Lines that where cut, are copied to the file 'cutlines.uvy', for manual
evaluation of the damage.
Anybody with TP 7.0 are encouraged to compile a version of the program,
that does not cut any lines.
All <space>-characters in the end of any line is removed in the process.
This feature is an integrated part of the whole algorithm.
The program allows the file to start with whatever before the first
news-message, and moves that to 'crapfile.uvy'.
The program detects the starting of a new message by the following
criteria:
After an empty line, all the required headers (according to RFC-1036)
are found among the headers before the next empty line (or max. 50 lines).
The required headers are:
"From:", "Date:", "Newsgroups:", "Subject:", "Message-ID:" and "Path:".
This algorithm is nearly 100% sure of detecting the start of a message,
but:
1. If a message contains a forwarded message, the forwarded message will
be regarded as a new message, if the 6 required headers are unchanged
and there is an empty line just before these headers.
2. If the first header is very wierd and therefore unknown (see the
is_header-function), the program will not regard it as the start of
a new message.
3. If the block of headers contains an empty line before the 6 required
headers have been found, the program will not regard it as the start
of a new message.
The program can _probably_ handle up to 8000 messages in one file,
depending only on allocated heap. The size of files only depend on the
diskspace for the temporary copy.
The program uses 2 passes:
1. It finds the starting points of messages, places '#! rnews' and
counts the size of the messages in bytes. These numbers are placed
in a list chained with pointers.
2. The numbers in the list are placed in the '#! rnews'-lines.
Well, there are actually 2 more passes (calling FLIP.EXE):
Before, all the files are converted to DOS-ASCII, by inserting <Carriage
Return> at newline (for Turbo Pascal to be able to handle them as text
files), and in the end they are converted (back) to UNIX-text-format,
by removing the <Carriage Return>s at all newlines, to create a real
rnews-batch.
(*) (The reason why Danish letters can be used in Turbo Pascal source code,
is that from the begining as COMPAS Pascal in 1982 (or earlier?), and
until now, TP has been developed by a Dane, Anders Hejlsberg.
He programmed the Pascal-compiler in Z80-assembler in his spare time
while studying Bachelor in Computer Science. I believe that he invented
the idea of an integrated, interactive program-development environment,
know called IDE, thereby making the big, clumsy, and time-consuming
error-recovery procedures obsulete in the compiler.)
}
program nnrnews;
{$I-}
{$M 16000,0,65000 }
uses dos,crt;
type
int_point = ^longint_rec;
longint_rec = record
count: longint;
next: int_point;
end;
var
first_pointer, last_pointer, temp_pointer
: int_point;
empty_line, empty_oldline, is_from, is_date, is_newsg, is_subj, is_mess,
is_path, all_headers, is_a_header, is_newsfile
: boolean;
infil, udfil, crapfile, cutlinefile
: text;
l, i, str_count : integer;
message_counter : longint;
streng, streng2, streng3 : string;
str_arr : array[1..50] of string;
dirinfo : searchrec;
procedure required_heads(streng:string);
begin
{ The required headers: "From:", "Date:", "Newsgroups:", "Subject:",
"Message-ID:" and "Path:" }
if copy(streng,1,5)='Path:' then is_path:=true else
if copy(streng,1,11)='Newsgroups:' then is_newsg:=true else
if copy(streng,1,5)='From:' then is_from:=true else
if copy(streng,1,5)='Date:' then is_date:=true else
if copy(streng,1,8)='Subject:' then is_subj:=true else
if copy(streng,1,10)='Message-ID' then is_mess:=true else
if copy(streng,1,10)='Message-id' then is_mess:=true;
end;
function is_header(streng:string): boolean;
var is_head : boolean;
{ I believe this function is quite time-optimal! }
begin
if streng='' then is_head:=false else
if copy(streng,1,1)='-' then is_head:=false else
if copy(streng,1,1)=' ' then is_head:=false else
{ The required headers: "From:", "Date:", "Newsgroups:",
"Subject:", "Message-ID:" and "Path:" }
if copy(streng,1,5)='Path:' then
begin is_head:=true; is_path:=true end else
if copy(streng,1,11)='Newsgroups:' then
begin is_head:=true; is_newsg:=true end else
begin
is_head:=false;
if copy(streng,1,5) = 'From:' then
begin is_head:=true; is_from:=true end;
if copy(streng,1,5) = 'Date:' then
begin is_head:=true; is_date:=true end;
if copy(streng,1,8) = 'Subject:' then
begin is_head:=true; is_subj:=true end;
if copy(streng,1,10) = 'Message-ID' then
begin is_head:=true; is_mess:=true end;
if copy(streng,1,10) = 'Message-id' then
begin is_head:=true; is_mess:=true end;
if copy(streng,1,5) = 'Xref:' then is_head:=true;
if copy(streng,1,8) = 'Expires:' then is_head:=true;
if copy(streng,1,8) = 'Control:' then is_head:=true;
if copy(streng,1,13) = 'Distribution:' then is_head:=true;
if copy(streng,1,9) = 'Keywords:' then is_head:=true;
if copy(streng,1,8) = 'Summary:' then is_head:=true;
if copy(streng,1,9) = 'Approved:' then is_head:=true;
if copy(streng,1,9) = 'Comments:' then is_head:=true;
if copy(streng,1,6) = 'Lines:' then is_head:=true;
if copy(streng,1,13) = 'MIME-Version:' then is_head:=true;
if copy(streng,1,13) = 'MIME-version:' then is_head:=true;
if copy(streng,1,13) = 'Mime-V